#!/usr/bin/env python
# coding: utf-8

# In[52]:


import pandas as pd
data = pd.read_csv(r'C:\Users\l\Desktop\final-progect\AI\数据集\data_collection.csv')


# In[53]:


data.head(5)


# In[54]:


data.values


# In[55]:


dataset = data.values


# In[56]:


x = dataset[:,:-1]
y = dataset[:,-1]


# In[57]:


from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2, random_state=42)


# In[58]:


x_train = x_train.reshape((x_train.shape[0], 1, x_train.shape[1]))
x_test = x_test.reshape((x_test.shape[0], 1, x_test.shape[1]))


# In[59]:


import numpy
import matplotlib.pyplot as plt
import pandas
import math

from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout
from sklearn.preprocessing import MinMaxScaler
# from sklearn.metrics import mean_squared_erro


# In[62]:


model = Sequential()
model.add(LSTM(64, input_shape=(x_train.shape[1], x_train.shape[2])))
model.add(Dropout(0.01))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
history=model.fit(x_train,y_train,epochs=600,batch_size=16,validation_data=(x_test, y_test), verbose=2, shuffle=False)


# In[63]:


from matplotlib import pyplot
pyplot.plot(history.history['loss'], label='train')
pyplot.plot(history.history['val_loss'], label='test')
pyplot.legend()
pyplot.show()


# In[83]:


import datetime,time

current = datetime.date.today()
pred = []
for i in range(1,21):
    tor = current+datetime.timedelta(days=1)
    pred.append({'a':104749,'b':time.mktime(tor.timetuple()),'c':90,'d':5.55,'e':11,'f':17,'g':7})


# In[85]:


pred = pd.DataFrame(pred).values
pred


# In[86]:


pred = pred.reshape((pred.shape[0],1,pred.shape[1]))


# In[87]:


model.predict(pred)


# In[88]:


model.save(r'C:\Users\l\Desktop\final-progect\selfDesign.h5')


# In[ ]:




